define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 'modalSearch' , 'shiftform'],
    function ($, validate) {
        return {

            init: function () {
                this.initEdit();
                this.initPage();
            },

            initEdit: function () {

                $(document).find('form').bt_validate();

                $('select[name="organization"]').select2({
                    theme: "classic",
                    placeholder: '请选择',
                    minimumResultsForSearch: -1,
                    allowClear: true,
                });

                $('select[name="gender"]').select2({
                    placeholder: '请选择',
                    minimumResultsForSearch: -1,
                    allowClear: true,
                });

                $('select[name="educationLevel"]').select2({
                    placeholder: '请选择',
                    minimumResultsForSearch: -1,
                    allowClear: true,
                });

                $('select[name="dutyId"]').select2({
                    placeholder: '请选择',
                    minimumResultsForSearch: -1,
                    allowClear: true,
                });

                $('select[name="clanId"]').select2({
                    placeholder: '请选择',
                    minimumResultsForSearch: -1,
                    allowClear: true,
                });

                $('select[name="degreeId"]').select2({
                    placeholder: '请选择',
                    minimumResultsForSearch: -1,
                    allowClear: true,
                });

            },
            
            initPage: function () {

                $(document).on("shown.bs.modal", "#edit", function (e) {

                    $(e.currentTarget).find('form[data-validate="true"]').bt_validate()  //bind validate

                    var $form = $(e.currentTarget).find("form")                          //bind shiftform
                    $form.shiftform({
                        beforeSubmit: function (el) {
                            $form.trigger("validate.ajax.submit");
                            return $.bt_validate.result[$.bt_validate.form_id]
                        }
                    })
                });
            },
        }
    })